package com.cskaoyan.service.pz;

import com.cskaoyan.bean.pz.ColumnsAndRowBean;
import com.cskaoyan.bean.pz.GoodsRowsBean;
import com.cskaoyan.bean.pz.OrderRowsBean;
import com.cskaoyan.bean.pz.UserRowsBean;
import com.cskaoyan.mapper.pz.StatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
class StatServiceImpl implements StatService {

    @Autowired
    StatMapper statMapper;

    @Override
    public ColumnsAndRowBean<UserRowsBean> queryStatUser() {
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");

        List<UserRowsBean> userRowsBean = statMapper.selectStateUser();

        return ColumnsAndRowBean.data(columns, userRowsBean);
    }

    @Override
    public ColumnsAndRowBean<OrderRowsBean> queryStatOrder() {
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");

        List<OrderRowsBean> orderRowsBean = statMapper.selectStateOrder();

        for (OrderRowsBean rowsBean : orderRowsBean) {
            rowsBean.setPcr(rowsBean.getAmount() / rowsBean.getCustomers());
        }
        return ColumnsAndRowBean.data(columns,orderRowsBean);
    }

    @Override
    public ColumnsAndRowBean<GoodsRowsBean> queryStatGoods() {
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");

        List<GoodsRowsBean> goodsRowsBean = statMapper.selectStateGoods();

        return ColumnsAndRowBean.data(columns,goodsRowsBean);
    }
}